package com.smartpro.mis.modular.business.controller;

import com.alibaba.fastjson.JSONObject;
import com.smartpro.mis.core.base.controller.BaseController;
import com.smartpro.mis.rest.modular.auth.controller.dto.ResponseBean;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.ui.Model;
import org.springframework.beans.factory.annotation.Autowired;
import com.smartpro.mis.modular.system.model.Tags;
import com.smartpro.mis.modular.business.service.ITagsService;

/**
 * rest控制器
 *
 * @author Mengiy
 * @Date 2019-05-07 21:50:05
 */
@RestController
@RequestMapping("/api/service/tags")
public class TagsController extends BaseController {
    @Autowired
    private ITagsService tagsService;

    /**
     * 获取rest列表
     */
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    @ResponseBody
    @RequiresAuthentication
    public Object list() {
        return new ResponseBean(200,"query success",tagsService.selectList(null));
    }

    /**
     * 新增rest
     */
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @ResponseBody
    @RequiresAuthentication
    public Object add(@RequestBody Tags tags) {
        tagsService.insert(tags);
        return  new ResponseBean(200,"operation success", JSONObject.toJSON(tags));
    }

    /**
     * 删除rest
     */
    @RequestMapping(value = "/delete",method = RequestMethod.GET)
    @ResponseBody
    @RequiresAuthentication
    public Object delete(@RequestParam Integer tagsId) {
        tagsService.deleteById(tagsId);
        return new ResponseBean(200,"operation success", null);
    }

    /**
     * 修改rest
     */
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ResponseBody
    @RequiresAuthentication
    public Object update(@RequestBody Tags tags) {
        tagsService.updateById(tags);
        return new ResponseBean(200,"operation success", JSONObject.toJSON(tags));
    }

    /**
     * rest详情
     */
    @RequestMapping(value = "/detail/{tagsId}",method = RequestMethod.GET)
    @ResponseBody
    @RequiresAuthentication
    public Object detail(@PathVariable("tagsId") Integer tagsId) {
        return new ResponseBean(200,"query success", tagsService.selectById(tagsId));
    }
}
